package com.example.flshtarvel.service;

import com.example.flshtarvel.entity.ArticleLikeMap;
import com.example.flshtarvel.entity.RouteLikeMap;
import com.example.flshtarvel.mapper.ArticleLikeMapMapper;
import com.example.flshtarvel.mapper.RouteLikeMapMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RouteLikeMapService {
    @Autowired(required = false)
    RouteLikeMapMapper routeLikeMapMapper;

    //信息点赞
    public int routeLike(String routeId, String userId){
        List<RouteLikeMap> routeLikeMaps = routeLikeMapMapper.selectRouteLikeByRouteIdAndUserId(routeId,userId);
        if(routeLikeMaps.size()==0 || routeLikeMaps==null){
            int result = routeLikeMapMapper.routeLike(routeId,userId);
            return result;
        }else{
            return 0;
        }
    }

    //取消点赞
    public int deleteRouteLike(String routeId,String userId){
        int result = routeLikeMapMapper.deleteRouteLike(routeId,userId);
        return result;
    }

    //查询点赞    根据信息id 用户id
    public int selectRouteLikeByRouteIdAndUserId(String routeId, String userId){
        List<RouteLikeMap> routeLikeMaps = routeLikeMapMapper.selectRouteLikeByRouteIdAndUserId(routeId,userId);
        int result;
        if(routeLikeMaps.size()==0||routeLikeMaps==null){
            result=0;
        }else{
            result=1;
        }
        return result;
    }

    //查询点赞数    根据信息id
    public int selectRouteLikeByRouteId(String routeId){
        int result = routeLikeMapMapper.selectRouteLikeByRouteId(routeId);
        return result;
    }
}
